<template>
  <div class="wrap">
    <el-form>
      <el-form-item label="请选择分类">
        <el-input
          :style="{ width: '50%' }"
          v-model="searchValue"
          placeholder="请搜索您想要的产品"
        ></el-input>
        <el-button @click="onsearchit">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="list" style="width: 100%">
      <el-table-column type="index" label="序号" width="80"></el-table-column>
      <el-table-column
        class-name="pro-name"
        prop="goods_name"
        label="名称"
        width="350"
      ></el-table-column>
      <el-table-column sortable prop="goods_price" label="原价" width="180">
        <!-- sortable是el-table-column中的排序小属性 -->
      </el-table-column>
      <el-table-column sortable prop="goods_id" label="ID" width="180">
      </el-table-column>
      <el-table-column
        prop="goods_number"
        label="数量"
        width="180"
      ></el-table-column>
      <el-table-column label="操作" width="180">
        <template v-slot:default="xxx">
          <el-button @click="delPro(xxx.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
      class="right"
      background
      :current-page.sync="page"
      :page-size="pageSize"
      layout="prev, pager, next"
      :total="total"
    ></el-pagination>
  </div>
</template>

<script>
import _ from "lodash";
import { RomoveProductionList, getProductionList } from "@/api/production.js";
// import { requestList } from "@/utils/index.js";
export default {
  data() {
    return {
      list: [],
      total: 0,
      pageSize: 10,
      page: 1,
      // 当前选择的产品
      value: "",
      // 当前的所有产品分类
      options: [],

      // 搜索项
      searchValue: "",
    };
  },
  methods: {
    //删除商品数据
    delPro(proItem) {
      RomoveProductionList(proItem.goods_id).then((res) => {
        // console.log(res);
        this.requestList();
      });
    },
    onsearchit() {
      this.requestList();
    },
    requestList() {
      getProductionList({
        pagenum: this.page,
        pagesize: this.pageSize,
      }).then((res) => {
        // console.log(res);
        if (res.data.meta.status === 200) {
          this.list = res.data.data.goods;
          // 更新总数
          this.total = res.data.data.total;
        }
      });
    },
  },
  mounted() {
    this.requestList();
  },
  watch: {
    page: "onsearchit",
  },
};
</script>

<style scoped lang="scss">
.wrap{
  margin-top: 10px;
}
</style>
